<?php


->快速上手
  官网: https://github.com/seata/seata-samples

  1. [下载.seata-server]
     . /conf/file.conf: (配置[seata数据库地址] (mysql.sql / [global_table + branch_table + lock_table]))
     . register.conf: (配置注册中心配置)

  2. [pom]
     https://github.com/seata/seata-samples
     <dependency>
         <groupId>com.alibaba.cloud</groupId>
         <artifactId>spring-cloud-alibaba-seata</artifactId>
         <version>2.1.0.RELEASE</version>
         <exclusions>
             <exclusion>
                 <artifactId>seata-all</artifactId>
                 <groupId>io.seata</groupId>
             </exclusion>
         </exclusions>
     </dependency>
     <dependency>
        <groupId>io.seata</groupId>
        <artifactId>seata-all</artifactId>
        <version>1.4.2</version>
     </dependency>


  3. [补偿日志]
     为每个服务器创建'补偿日志表' (因为是要基于这个日志做补偿, 但是是'一次性'的, 补偿完毕后会: [ rm handle branch ])
     详见: 附录/mysql.sql-undo_log
     注意: 只针对'AT模式'

  4. [配置]
     . 配置类 (详见: 附录/DataSourceConfiguration.java)
     . resource (附录/file.conf | registry.conf)

     [file.conf]
     service {
       // vgroupMapping.[项目名称]
       vgroupMapping.my_test_tx_group = "default"
       default.grouplist = "127.0.0.1:8091"
     }
     - spring.cloud.alibaba.seata.txServiceGroup=my_test_tx_group

     spring配置，springboot可配置在yml、properties中，服务启动时加载配置，对应的值'my_test_tx_group'即为一个事务分组名，
     若不配置，默认获取属性 [ spring.application.name的值 + '-fescar-service-group' ]

     注意: 多个微服务只能配置'一个事务管理器'
     @Bean
     public PlatformTransactionManager txManager(DataSource dataSourceProxy) {
         return new DataSourceTransactionManager(dataSourceProxy);
     }

  5. [使用]
     @GlobalTransactional
     @PostMapping("/saveOne2Transaction")
     public User saveOne2Transaction() {
          // do something...
     }

  6. [启动]
     . Eureka
     . seata-server (如果使用了[注册中心], 那么将[seata-server]注册上去, (register.conf))
     . services...



报错解决:
1. 如果没有配置[txManager]的服务无法启动, 那么在[配置文件]中添加

private static final String MAPPER_LOCATION = "classpath*:mapper/*.xml";

@Bean
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSourceProxy") DataSource dataSourceProxy) throws Exception {
    MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSourceProxy);
    sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
    return sessionFactory.getObject();
}
